import { defineStore } from 'pinia'
import { type userTable } from '@/api/login/userTable'

export const useUserStore = defineStore('user', {
  state: (): { user: userTable | null } => ({
    user: null
  }),
  actions: {
    // 设置用户信息
    setUserInfo(info: userTable) {
      this.user = info
    },
    // 清空用户信息
    clearUserInfo() {
      this.user = null
    }
  },
  // 持久化配置，将数据存储到 localStorage
  persist: {
    storage: localStorage,
  },
})
